package func;

public class FunctionFactory {
	
	public static Function createAdd() {
		return new
			Function() {
				public int applyFunction(int[] param) {
					return param[0] + param[1];
				}
				
				public int getChildcount() {
					return 2;
				}
				
				public String toString() {
					return "add";
				}
			};
	}
	
	public static Function createSub() {
		return new
			Function() {
				public int applyFunction(int[] param) {
					return param[0] - param[1];
				}
				
				public int getChildcount() {
					return 2;
				}
				
				public String toString() {
					return "subtract";
				}
			};
	}
	
	public static Function createMult() {
		return new
			Function() {
				public int applyFunction(int[] param) {
					return param[0]*param[1];
				}
				
				public int getChildcount() {
					return 2;
				}
				
				public String toString() {
					return "multiply";
				}
			};
	}
	
	public static Function createIf() {
		return new
			Function() {
				public int applyFunction(int[] param) {
					if(param[0] > 0)
						return param[1];
					else
						return param[2];
				}
				
				public int getChildcount() {
					return 3;
				}
				
				public String toString() {
					return "if";
				}
			};
	}
	
	public static Function createIsGreater() {
		return new
			Function() {
				public int applyFunction(int[] param) {
					if(param[0] > param[1])
						return 1;
					else
						return 0;
				}
				
				public int getChildcount() {
					return 2;
				}
				
				public String toString() {
					return "isgreater";
				}
			};
	}
	
	public static Function createIsEqual() {
		return new
			Function() {
				public int applyFunction(int[] param) {
					if(param[0] == param[1])
						return 1;
					else
						return 0;
				}
				
				public int getChildcount() {
					return 2;
				}
				
				public String toString() {
					return "isequal";
				}
			};
	}
	
	public static Function[] getFunctions() {
		return new Function[]{
				createAdd(),
				createSub(),
				createMult(),
				createIf(),
				createIsGreater(),
				createIsEqual()
			};
	}
}
